package Starter;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;

import java.awt.Image;

import java.io.File;
import java.io.IOException;
import java.util.Vector;

import javax.imageio.ImageIO;
import javax.swing.*;

import Components.CreatorPanel;
import Components.ImageButton;
import Components.RoomsPanel;
import Connector.Connector;

import smash_tris.*;

/** 
 * Klasa odpowiedzialna za wyďż˝wietlanie Menu
 * @author Maciej Graszej
 * @author Paweďż˝ Rychďż˝y
 *
 */
public class Menu extends JPanel {
			
	/* Informacje o grze */
	private Player player;
	private Vector<Room> roomsList;
	
	/* TĹ‚o */
	private Image background;
	
	/* Elementy z menu */
	private ImageButton exit;
	private RoomsPanel roomsPane;
	private JScrollPane scroll;
	private CreatorPanel creator;
		
	private static int width = 707;
	private static int heigh = 530;
	
	/* Reszta */
	private String DIR = "picture/menu_pics/";
	private boolean aLife = false;
	private MainFrame mainFrame = null;
	private Connector connector = null;

	public Menu(Player player, MainFrame mainFrame, Vector<Room> rooms) {
		//this.setLayout(new GridBagLayout());
		this.setLayout(null);
		
		
		this.mainFrame = mainFrame;
		this.connector = mainFrame.getConnector();
		mainFrame.setSize(width,heigh);
		this.roomsList = rooms;
		try {
			background = ImageIO.read(new File(DIR + "menu_background.jpg"));
		} catch (IOException e) {
			System.err.println("BĹ‚Ä…d podczas zaĹ‚adowania tĹ‚a w menu");
			e.printStackTrace();
		}
		
		this.setOpaque(true);
		initComponents();
		
	}

/*-----------METODY NADPISANE----------------------*/
	
    @SuppressWarnings("unchecked")	
	private void initComponents() {
    	
    	exit = new ImageButton(DIR+"exit_UP.png",DIR+"exit_DOWN.png");
    	exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                connector.close();
            	System.exit(-1);
            }
        });

    	roomsPane = new RoomsPanel(this.roomsList, this, connector);
    	

		scroll = new JScrollPane(roomsPane);
		scroll.setPreferredSize(new Dimension(300, 400));
		scroll.setBackground(new Color(255,255,255,50));
		
		creator = new CreatorPanel(this);
		
		scroll.setBounds(10, 10, 300, 400);
    	exit.setBounds(width - 100, heigh - 100,62,62);
    	creator.setBounds(350, 10, 250, 85);
    	
    	this.add(exit);
		this.add(scroll);
		this.add(creator);
				
    			
	}
    
    /**
     * Metoda rysujaca (gďż˝ďż˝wnie) tďż˝o
     */
	@Override
	public void paintComponent(Graphics g) {
	    Graphics2D g2 = (Graphics2D) g;
	    
	    g2.drawImage(background, 0, 0, null);	    
	}


	public MainFrame getMainFrame() {
		return mainFrame;
	}

	/**
	 * Metoda zwraca referencę do panelu pokoi.
	 * @return panel pokoi.
	 */
	public RoomsPanel getRoomsPane() {
		return roomsPane;
	}
	
	/**
	 * Metoda zwraca obiekt Connectora.
	 * @return Obiekt connecotra.
	 */
	public Connector getConnector() {
		return this.connector;
	}
	
	public Player getPlayer() {
		return this.player;
	}
	
	public CreatorPanel getCreator() {
		return creator;
	}
	

}
